import dateOptions from "@/utils/date"; //引入date的渲染
import {findPage,findAllIndent,deleteById,searchIndentById,searchCountGoods} from '@/api/indentMarket';//引入axios的请求
import {updateIndent,searchNowTime} from '@/api/indent';
let market = {
    // name: "index",
    data() {
        return {
            tableData: [],//数据信息
            total:0,//总条数
            indentTypeList:[],//订单类型集合
            payTypeList:[],//支付方式集合
            indentActionList:[],//订单动作集合
            indentStateList:[],//订单状态集合
            searchFroms: {
                currentPage: 1,//当前页
                pageSize: 5,//每页显示条数
                startTime: '',//开始时间
                endTime: '',//结束时间
            },
            formData:[],//新增表单信息
            dateOptions,
            batchIds:[],//批量删除  判断选中是否修改 和删除
            dialogVisible: false,//新增窗口默认不开
            dialogVisible1:false,
            backIndent:[],
            countGoods:[],
            buttonId:"",
            indentData:{}

        }
    },
    created() {//回调函数
        // console.log("asd1")
        //查询
        this.searchPage();
        this.searchAllIndent();


    },
    methods: {
        /**
         * 查询所有
         */
        async searchPage() {
            //执行查询
            let response = await findPage(this.searchFroms);
            console.log(response);
            this.total = response.total;//总行数复制
            this.tableData = response.data;//数据信息赋值

        },
        //时间框 选择时间
        chooseTime() {
            this.searchFroms.startTime = this.dateOptions.startDate[0];
            this.searchFroms.endTime = this.dateOptions.startDate[1];
        },
        /**
         * 查询所有订单信息
         */
        async searchAllIndent(){
            //所有的订单信息
           let response = await findAllIndent();
            // console.log(response);
            let arr=[];
            //赋值订单类型
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].indentType;
            }
            //去掉支付方式中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.indentTypeList.indexOf(arr[i]) === -1){
                    this.indentTypeList.push(arr[i]);
                }
            }

            //赋值支付方式
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].payType;
            }
            // console.log(arr);
            //去掉支付方式中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.payTypeList.indexOf(arr[i]) === -1){
                    this.payTypeList.push(arr[i]);
                }
            }

            //赋值订单动作
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].indentAction;
            }
            //去掉订单动作中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.indentActionList.indexOf(arr[i]) === -1){
                    this.indentActionList.push(arr[i]);
                }
            }

            //赋值订单状态
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].indentState;
            }
            //去掉订单状态中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.indentStateList.indexOf(arr[i]) === -1){
                    this.indentStateList.push(arr[i]);
                }
            }
        },
        //点击下一页 发生改变
        currentPageChange(page) {
            this.searchFroms.currentPage = page;//当前页赋值
            this.searchPage();//刷新页面
        },
        //点击查询赋值
        findIndentBylike(){
          this.searchPage();
        },
        resetForm(){
            this.searchFroms.currentPage =1;
            this.searchFroms.pageSize =5;
            this.searchFroms.startTime = '';
            this.searchFroms.endTime = '';
            this.searchFroms.id='';
            this.searchFroms.indentType = '';
            this.searchFroms.payType = '';
            this.searchFroms.indentState = '';
            this.searchFroms.indentAction = '';
            this.dateOptions.startDate = '';
            // 重置后重新加载页面

            this.searchPage();
        },

        /**
         * 通过id删除
         */
        async deleteByIndentId() {
            // console.log(this.formData.id);
            await deleteById(this.formData.id);
            this.searchPage();
        },
        //checkbox勾选改变
        selectChange(val) {
            // console.log(val);
            /**
             * 复选框选择修改 进行id赋值
             */
            if (val.length===1){
                //id赋值
                this.formData.id=val[0].id;
            }else {
                this.formData.id="";
            }
            //勾选二个的时候修改失效  删除有效
            this.batchIds = val.map(item => item.id)


        },

        async findIndentByid(){
            console.log("调用findIndentByid方法");
            // console.log(this.formData.id);
            let response = await searchIndentById(this.formData.id);
            // console.log(response);
            this.backIndent=response;
            // console.log(this.backIndent);
        },
        async findCountGoods(){
            console.log("调用findCountGoods方法");
            // console.log(this.formData.id);
            let response = await searchCountGoods(this.formData.id);
            // console.log(response);
            this.countGoods=response;
            // console.log(this.countGoods);
        },
        //根据订单id修改创建者和创建时间
        async updateIndentById(){

            this.indentData.id=this.formData.id;
            console.log(this.indentData);
            await updateIndent(this.indentData);
        },



    }


};

export default market;